# service_provider.py
from fastapi import FastAPI
from tortoise.contrib.fastapi import register_tortoise

from api import routers
from utils.consul_utils import register_service

app = FastAPI()
for router in routers:
    app.include_router(router)


@app.get("/health")
async def health_check():
    return {"status": "healthy"}  # 必须返回200


register_tortoise(
    app,
    db_url="mysql://guducat:guducat@106.55.190.148:3306/ruoyi-fastapi",
    modules={"models": ["model.user_model"]},
    generate_schemas=True,
    add_exception_handlers=True,
)

if __name__ == "__main__":
    import uvicorn

    register_service("admin-provider", 8000)
    uvicorn.run(app, host="0.0.0.0", port=8000)
